package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.UserEcologyPoints;
import com.sc.nft.entity.UserEcologyPointsWallet;
import com.sc.nft.entity.vo.AdminDaoEcologyPointWalletPageVO;
import com.sc.nft.entity.vo.AdminEcologyPointsUserWalletPageVO;
import com.sc.nft.entity.vo.AdminUserEcologyPointWalletPageVO;
import com.sc.nft.entity.vo.ecology.AdminEcologyPointsUserPageVO;
import com.sc.nft.entity.vo.ecology.EcologyPointWalletExpendPageVO;
import com.sc.nft.entity.vo.ecology.EcologyPointWalletPageVO;
import com.sc.nft.mapper.UserEcologyPointsWalletMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：DaoEcologyPointsWalletDao
 * @Date：2024/11/26 11:08
 * @Filename：DaoEcologyPointsWalletDao
 */
@Slf4j
@Repository
public class UserEcologyPointsWalletDao extends ServiceImpl<UserEcologyPointsWalletMapper, UserEcologyPointsWallet> {
    public UserEcologyPointsWallet getOneByUserIdAndPointId(Long pointsId, Long userId) {
        LambdaQueryWrapper<UserEcologyPointsWallet> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserEcologyPointsWallet::getUserId, userId).eq(UserEcologyPointsWallet::getPointsId, pointsId).last("order by id desc limit 1");
        return getOne(queryWrapper);
    }

    public Boolean addAmount(Long id, BigDecimal amount, BigDecimal oldAmount) {
        return baseMapper.addAmount(id, amount, oldAmount);
    }

    public Boolean subAmount(Long id, BigDecimal amount, BigDecimal oldAmount) {
        return baseMapper.subAmount(id, amount, oldAmount);
    }

    /**
     * 用户积分列表
     * @param pageNo
     * @param pageSize
     * @param userCreatorId
     * @return
     */
    public IPage<EcologyPointWalletPageVO> userPage(Integer pageNo, Integer pageSize, Long userCreatorId,Long userId) {
        return baseMapper.userPage(new Page<>(pageNo,pageSize),userCreatorId,userId);
    }

    public IPage<EcologyPointWalletExpendPageVO> userEcologyPointsExpend(Integer pageNo, Integer pageSize, Long userPointsWalletId, Long userId) {
        return baseMapper.userEcologyPointsExpend(new Page<>(pageNo,pageSize),userPointsWalletId,userId);
    }


    public Page<AdminEcologyPointsUserWalletPageVO> getUserPage(String userTel, Integer pageNo, Integer pageSize) {
        return baseMapper.getUserPage(new Page<>(pageNo, pageSize), userTel);
    }

    public IPage<AdminUserEcologyPointWalletPageVO> adminUserPointWalletPage(Integer pageNo, Integer pageSize,  Long userId) {
        return baseMapper.adminUserPointWalletPage(new Page<>(pageNo,pageSize),userId);
    }

    public IPage<AdminDaoEcologyPointWalletPageVO> adminDaoPointWalletPage(Integer pageNo, Integer pageSize, Long userCreatorId) {
        return baseMapper.adminDaoPointWalletPage(new Page<>(pageNo,pageSize),userCreatorId);
    }

    public  BigDecimal getUserBalanceAmount(Long pointsId) {
        return baseMapper.getUserBalanceAmount(pointsId);
    }


    public UserEcologyPointsWallet getOneByUserId(Long userId) {
        LambdaQueryWrapper<UserEcologyPointsWallet> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserEcologyPointsWallet::getUserId, userId);
        return getOne(wrapper);
    }


    public Boolean addEcologyPoints(Long userId, BigDecimal amount) {
        return baseMapper.addEcologyPoints(userId, amount);
    }
}
